package com.aji.wineserver.controllerBase;

import com.baomidou.mybatisplus.extension.service.IService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import com.aji.winecommon.result.Result;
import java.util.List;
//用来参考
public class ControllerBase<M extends IService<T>,T>{
    @Autowired
    M iService;
    @ApiOperation("增加 需要忽略id")
    @PreAuthorize("hasAuthority('admin')")
    @PostMapping()
    public Result save(@RequestBody T entity){
        iService.save(entity);
        return Result.success();
    }
    @ApiOperation("删除")
    @DeleteMapping("/{ids}")
    @PreAuthorize("hasAuthority('admin')")
    public Result delete(@PathVariable List<Integer> ids){
        iService.removeByIds(ids);
        return Result.success();
    }
    @ApiOperation("修改")
    @PreAuthorize("hasAuthority('admin')")
    @PutMapping()
    public Result updateById(@RequestBody  T entity){
        iService.updateById(entity);
        return Result.success();
    }
    @ApiOperation("查询 根据id")
    @PreAuthorize("hasAuthority('admin')")
    @GetMapping("/{id}")
    public Result getById(@PathVariable Integer id){
        return Result.success(iService.getById(id));
    }
    @ApiOperation("查询 全部")
    @PreAuthorize("hasAuthority('admin')")
    @GetMapping("/list")
    public Result list(){
        return Result.success(iService.list(null));
    }
//    @ApiOperation("查询 分页 条件")
//    @GetMapping("/{page}/{pageSize}")
//    public Result pageList(@PathVariable Integer page,@PathVariable Integer pageSize,String name){
//        Page<Game> rowPage = new Page(page, pageSize);
//        LambdaQueryWrapper<Game> wrapper = new LambdaQueryWrapper<Game>()
//                .select()
//                .like(Game::getName,name);
//        return Result.success(gameService.page(rowPage,wrapper));
//    }
}
